//
//  LoverViewCell.m
//  Emoticon
//
//  Created by ytkjs2 on 2020/4/1.
//  Copyright © 2020 ytk. All rights reserved.
//

#import "LoverViewCell.h"

@interface LoverViewCell ()

@property (nonatomic, strong)UIButton * btn1, * btn2;

@property (nonatomic, strong)UIButton * download;

@end


@implementation LoverViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    CGFloat width = (rScreenWidth - 27)/2;
//    return width * 2436/1370;
    _btn1 = [UIButton buttonWithType:UIButtonTypeCustom];
    [_btn1 setFrame:CGRectMake(9, 0, width, width * rScreenHeight/rScreenWidth - 9)];
    [self.contentView addSubview:_btn1];
    
    _btn2 = [UIButton buttonWithType:UIButtonTypeCustom];
    [_btn2 setFrame:CGRectMake(18 + width, 0, width, width * rScreenHeight/rScreenWidth - 9)];
    [self.contentView addSubview:_btn2];
    
    _download = [[UIButton alloc]initWithFrame:CGRectMake(rScreenWidth/2 - 42, CGRectGetMaxY(_btn1.frame) - 14, 85, 28)];
    [_download.layer setMasksToBounds:YES];
    [_download.layer setCornerRadius:4.5];
    _download.backgroundColor = APP_THEME_COLOR;
    [_download setTitle:@"一起下载" forState:0];
    [_download setTitleColor:[UIColor whiteColor] forState:0];
    _download.titleLabel.font = [UIFont boldSystemFontOfSize:12];
    [self.contentView addSubview:_download];
}

-(void)setBtnWithImage:(NSArray *)imgArr withTag:(NSInteger)tag
{
    
    NSString * imgUrl1 = [imgArr[0] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    [_btn1 sd_setImageWithURL:[NSURL URLWithString:imgUrl1] forState:0 placeholderImage:[UIImage imageNamed:@"icon_placeholderImage"]];
    [_btn1.layer setMasksToBounds:YES];
    [_btn1.layer setCornerRadius:4.5];
    _btn1.tag = tag * 2;
    [_btn1 addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
    
    NSString * imgUrl2 = [imgArr[1] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    [_btn2 sd_setImageWithURL:[NSURL URLWithString:imgUrl2] forState:0 placeholderImage:[UIImage imageNamed:@"icon_placeholderImage"]];
    [_btn2.layer setMasksToBounds:YES];
    [_btn2.layer setCornerRadius:4.5];
    _btn2.tag = tag * 2 + 1;
    [_btn2 addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
    
    _download.tag = tag;
    [_download addTarget:self action:@selector(downloadAction:) forControlEvents:UIControlEventTouchUpInside];
    
}

-(void)btnAction:(UIButton *)btn
{
    [self.controller performSelector:@selector(btnAction:) withObject:btn];
}

//-(void)btn2Action:(UIButton *)btn
//{
//    [self.controller performSelector:@selector(btn2Action:) withObject:btn];
//}

-(void)downloadAction:(UIButton *)btn
{
    [self.controller performSelector:@selector(downloadAction:) withObject:btn];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
